Page({
  data: {
    banners: [],
    guides: [],
    backendUrl: 'http://127.0.0.1:88/api/user/'
  },

  onLoad() {
    this.loadBanners();
    this.loadGuides();
  },

  // 加载轮播图数据
  loadBanners() {
    wx.request({
      url: this.data.backendUrl + 'get_banners.php',
      success: (res) => {
        if (res.data.status === 'success') {
          this.setData({
            banners: res.data.banners
          });
        }
      }
    });
  },

  // 加载健身指南数据
  loadGuides() {
    wx.request({
      url: this.data.backendUrl + 'get_guides.php',
      success: (res) => {
        if (res.data.status === 'success') {
          this.setData({
            guides: res.data.guides
          });
        }
      }
    });
  },

  // 处理轮播图点击
  handleBannerClick(e) {
    const url = e.currentTarget.dataset.url;
    wx.navigateTo({
      url: url
    });
  },

  // 导航函数
  navigateToCoaches() {
    wx.switchTab({
      url: '/pages/coaches/coaches'
    });
  },

  navigateToBooking() {
    wx.switchTab({
      url: '/pages/booking/booking'
    });
  },

  navigateToForum() {
    wx.switchTab({
      url: '/pages/forum/forum'
    });
  },

  navigateToProfile() {
    wx.switchTab({
      url: '/pages/profile/profile'
    });
  },

  // 跳转到所有指南页面
  navigateToAllGuides() {
    wx.navigateTo({
      url: '/pages/guides/guides'
    });
  },

  // 跳转到指南详情
  navigateToGuideDetail(e) {
    const guideId = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: `/pages/guide-detail/guide-detail?id=${guideId}`
    });
  }
});